package com.ruicar.afs.cloud.account.common.dto;

import com.ruicar.afs.cloud.account.common.entity.AccountVoucherInfo;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/7/6 10:37
 */
@Data
public class AccountVoucherDto {
    @ApiModelProperty("凭证号")
    @NotBlank(message = "凭证号不能为空")
    private String voucherNo ;

    @ApiModelProperty("合同号")
    private String contractNo ;

    @ApiModelProperty("记账日期")
    private Date postingDate ;

    @ApiModelProperty("分录序号")
    @NotBlank(message = "分录序号不能为空")
    private Integer entryNo ;

    @ApiModelProperty("科目代码")
    @NotBlank(message = "科目代码不能为空")
    private String subjectCode ;

    @ApiModelProperty("科目名称")
    @NotBlank(message = "科目名称不能为空")
    private String subjectName ;

    @ApiModelProperty("借贷方向")
    @NotNull(message = "借贷方向不能为空")
    private String lendingDirection ;

    @ApiModelProperty("借方金额")
    @NotBlank(message = "借方金额不能为空")
    private BigDecimal debitAmt ;

    @ApiModelProperty("贷方金额")
    @NotBlank(message = "贷方金额不能为空")
    private BigDecimal creditAmt;

    @ApiModelProperty("摘要")
    @NotBlank(message = "摘要不能为空")
    private String explanation ;

    @ApiModelProperty("交易状态 枚举值：待发送，成功，失败")
    private String status;

    public static AccountVoucherDto convertFromDto(AccountVoucherInfo accountVoucherInfo) {
        AccountVoucherDto dto = new AccountVoucherDto();
        dto.setStatus( AfsEnumUtil.desc(accountVoucherInfo.getStatus()));
        dto.setContractNo(accountVoucherInfo.getContractNo());
        dto.setVoucherNo(accountVoucherInfo.getVoucherNo());
        dto.setPostingDate(accountVoucherInfo.getPostingDate());
        return dto;
    }
}


